extends CharacterBody2D
@export var health=100
signal hit
const RUN_SPEED=200.00
const ACCELERATION=RUN_SPEED/0.1
signal paraChanged

@onready var animate:AnimatedSprite2D=$AnimatedSprite2D

func _ready():
	self.add_to_group("player")
	$Timer.stop()
	pass

func _physics_process(delta):
	var direction := Input.get_vector("左", "右", "上", "下")
	direction = direction.normalized()  # 确保方向向量长度为1，保持速度一致
	if direction != Vector2.ZERO:#get_physics_process_delta_time()
		velocity = velocity.move_toward(direction * RUN_SPEED, ACCELERATION * delta)
		if $FSM/Parasit.parasitism==true and scale.x<=4 and scale.y<=4:
			$Timer.start(1)
			scale.x+=0.01
			scale.y+=0.01
		if scale.x>=2 and scale.y>=2 and $FSM/Parasit.parasitism==false:
			scale.x-=0.01
			scale.y-=0.01
		move_and_slide()

func take_hit(value:int):
	health=health-value
	#$CanvasLayer/TextureProgressBar.value=health
	$FSM.change_state(4)
	pass

